package com.sky.mapper;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 符健清
 * @version 1.0
 */
@SuppressWarnings({"all"})
@Mapper
public interface OrdersServiceMapper {
    /**
     * 分页条件查询 订单信息
     * @param orders
     * @return
     */

    List<Orders> pageSelectOrders(Orders orders);


    /**
     * 取消订单
     * @param ordersCancelDTO
     */
    @Update("update  orders  set  status=1,cancel_reason =#{cancelReason},cancel_time =current_timestamp() where  id=#{id} ")
    void cancelOrder(OrdersCancelDTO ordersCancelDTO);

    /**
     * 待接单数量
     * @return
     */
    @Select("select count(*) from orders where  status =2")
    Integer counToBeConfirmed();

    /**
     * 待派送的数量
     */
    @Select("select count(*) from orders  where  status =3")
       Integer  confirmed();

    /**
     * 派送中的数量
     */
    @Select("select count(*) from orders where  status=4 ")
    Integer  deliveryInProgress();

    /**
     * 完成订单
     * @param id
     */
    @Update(" UPDATE  orders  SET  STATUS=5  where   id=#{id}")
    void finishOrder(Integer id);

    /**
     *拒单
     * @param ordersRejectionDTO
     */
    @Update("UPDATE  orders  SET  STATUS=6 , rejection_reason =#{rejectionReason}  where  id=#{id}")
    void rejectionOrder(OrdersRejectionDTO ordersRejectionDTO);


    /**
     * 接单
     * @param id
     */
    @Update("update  orders  set status = 3  where  id=#{id}")
    void confirmOrder(Long id);

    /**
     *  id 查村订单
     * @param id
     * @return
     */
    @Select("select * from orders where  id=#{id}")
    List<Orders> selectOrdersById(Integer id);


    /**
     * 派送订单
     * @param id
     */
    @Update("update  orders  set status = 4 where   id=#{id}")
    void sendOrder(Integer id);
}
